package cn.juque.lucenecandy.core.datasync.listener.impl;

import cn.hutool.core.text.CharSequenceUtil;
import cn.juque.lucenecandy.core.base.BaseMessageEntity;
import cn.juque.lucenecandy.core.datasync.listener.IMsgWriteListener;
import cn.juque.lucenecandy.core.enums.DataSyncMsgTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>NullParamMsgWriteListener</li>
 * </ul>
 * @date 2024-02-02
 **/
@Slf4j
@Service("nullParamMsgWriteListener")
@Order(-999)
public class NullParamMsgWriteListener implements IMsgWriteListener {
    /**
     * 事前操作
     * <li>可实现监听器，根据需要变更、读取报文</li>
     *
     * @param messageEntity 消息实体
     * @return boolean: false 取消写入索引
     */
    @Override
    public Boolean before(BaseMessageEntity messageEntity) {
        return CharSequenceUtil.isNotEmpty(messageEntity.getClassName())
                && CharSequenceUtil.isNotEmpty(messageEntity.getSyncType())
                && CharSequenceUtil.isNotEmpty(messageEntity.getBody())
                && DataSyncMsgTypeEnum.WAIT_WRITE.getCode().equals(messageEntity.getMsgType());
    }

    /**
     * 事后操作
     * <li>可实现监听器，根据需要变更、读取报文</li>
     *
     * @param messageEntity 消息实体
     */
    @Override
    public void after(BaseMessageEntity messageEntity) {
        log.warn("class:{} found body null", messageEntity.getClassName());
    }
}
